package com.sgb.goods.view.adapter.order;

import androidx.databinding.ObservableBoolean;
import androidx.databinding.ViewDataBinding;

import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.goods.BR;
import com.sgb.goods.R;
import com.sgb.goods.entity.order.OrderPayDetailEntity;
import com.sgb.goods.utils.base.adapter.BaseCommonAdapter;

/**
 * 订单付款详情适配器
 *
 * @author cyj
 */
public class OrderPayDetailAdapter extends BaseCommonAdapter<OrderPayDetailEntity> {

    public ObservableBoolean isDaiQueRen = new ObservableBoolean();
    /**
     * 是否是采购订单，采购订单显示审批状态，销售订单没有审批状态，不显示
     **/
    public ObservableBoolean isPurchaseOrder = new ObservableBoolean();
    /**
     * 是否是线上付款
     */
    public ObservableBoolean isOnlinePayment = new ObservableBoolean();

    public OrderPayDetailAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder baseHolder, ViewDataBinding dataBinding, OrderPayDetailEntity entity) {
        dataBinding.setVariable(BR.adapter, this);
        dataBinding.setVariable(BR.viewModel, entity);
        if (entity.payState == 0) {
            baseHolder.setImageResource(R.id.goods_iv_process_state, R.mipmap.goods_icon_pay_waiting);
        } else if (entity.payState == 1) {
            baseHolder.setImageResource(R.id.goods_iv_process_state, R.mipmap.goods_icon_pay_freeze);
        } else if (entity.payState == 2) {
            baseHolder.setImageResource(R.id.goods_iv_process_state, R.mipmap.goods_icon_pay_successful);
        } else if (entity.payState == 4) {
            baseHolder.setImageResource(R.id.goods_iv_process_state, R.mipmap.goods_icon_pay_confirming);
        } else if (entity.payState == 50) {
            baseHolder.setImageResource(R.id.goods_iv_process_state, R.mipmap.goods_icon_order_paying);
        } else if (entity.payState == 60) {
            baseHolder.setImageResource(R.id.goods_iv_process_state, R.mipmap.goods_icon_pay_revoke);
        }

        //当付款状态为冻结中、支付成功、 线下付款确认中时，可点击查看付款详情
        if ((1 == entity.payState || 2 == entity.payState || 4 == entity.payState)) {
            baseHolder.addOnClickListener(R.id.goods_rl_container);
        }
    }

    /**
     * 设置是否待确认与履约中订单流转状态，用于显示隐藏某些字段
     *
     * @param orderProcessState orderProcessState    订单流程状态 1：待接单 2：待确认 3：履约中 4：已完成 5：已取消
     */
    public void setIsDaiQueRen(int orderProcessState) {
        isDaiQueRen.set(2 == orderProcessState || 1 == orderProcessState);
    }

    /**
     * 设置是否是采购订单-用于显示隐藏审批状态字段
     * 备注：目前只有采购订单里面的支付信息才显示审批状态
     *
     * @param orderType 订单类型 1：采购订单；2：销售订单。
     */
    public void setIsPurchaseOrder(String orderType) {
        isPurchaseOrder.set("1".equals(orderType));
    }

    public void setIsOnlinePayment(int paymentMethod) {
        isOnlinePayment.set(paymentMethod == 0);
    }

}
